using NHibernate;
using System;
using System.Data;
using System.Collections;
using System.Reflection;

namespace Serpis
{
	public class Persister : IPersister
	{
		public virtual void Save(object model)
		{
			ISession session= AppDbConnection.Instance.SessionFactory.OpenSession();
			
			session.SaveOrUpdate(model);
			
			session.Flush();
			
			session.Close();
		}

		public virtual object Load(Type type, object id)
		{
			ISession session= AppDbConnection.Instance.SessionFactory.OpenSession();
			
			object obj= session.Get(type, id);
			
			session.Close();
			
			return obj;
		}
		
		public void Delete(Type type, object obj)
		{
			ISession session= AppDbConnection.Instance.SessionFactory.OpenSession();
			
			session.Delete(type.Name, obj);
			
			session.Flush();
			
			session.Close();
		}
	}
}
